﻿using System;
using Token.Piker.BLL;
using System.Web.Security;
using Token.Piker.Common;

namespace Token.Piker.Web.Admin.Manager
{
    public partial class Show : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["Id"] == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(Request.Params["id"].Trim()))
            {
                string strid = Request.Params["id"];
                int ID = (Convert.ToInt32(strid));
                ViewState["ID"] = ID;
                ShowInfo(ID);
            }
        }

        private void ShowInfo(int ID)
        {
            Token.Piker.BLL.AdminBLL bll = new Token.Piker.BLL.AdminBLL();
            Token.Piker.Model.Admin model = bll.GetModel(ID);
            this.lblID.Text = model.ID.ToString();
            this.lblAdminName.Text = model.AdminName;
            this.lblRealName.Text = model.RealName;
            this.lblGender.Text = model.Gender.ToString() == "0" ? "男" : "女";
            this.lblBirthday.Text = Convert.ToDateTime(model.Birthday).ToLongDateString();
            this.lblAddTime.Text = Convert.ToDateTime(model.AddTime).ToLongDateString();
            this.lblQQ.Text = model.QQ;
            this.lblEmail.Text = model.Email;
            this.lblPhone.Text = model.Phone;
            this.lblLastLogTime.Text = Convert.ToDateTime(model.LastLogTime).ToString();
            if (model.Flag.ToString() == "0")
            {
                this.lblFlag.Text = "待审核";
            }
            if (model.Flag.ToString() == "1")
            {
                this.lblFlag.Text = "已审核";
            }
            if (model.Flag.ToString() == "2")
            {
                this.lblFlag.Text = "摄影部部长";
            }
            if (model.Flag.ToString() == "3")
            {
                this.lblFlag.Text = "已禁用";
            }

        }

        protected void lkbPassword_Click(object sender, EventArgs e)
        {
            //判断是否有权限重置密码
            if (Session[GlobalConstants.PIKER_ADMIN] == null)
            {
                MessageBox.Show(this.Page, "网络连接超时，请重新登录!");
                Response.Redirect("~/Admin/Login.aspx");
                return;
            }
            int currentAdminID = Convert.ToInt32(Session[GlobalConstants.PIKER_ADMIN]);
            AdminBLL adminBLL = new AdminBLL();
            Token.Piker.Model.Admin currentAdmin = adminBLL.GetModel(currentAdminID);
            if (currentAdmin.Flag != 3)
            {
                MessageBox.Show(this.Page,"您无权进行该操作！");
                return;
            }
            int id = Convert.ToInt32(ViewState["ID"]);
            Token.Piker.Model.Admin admin = adminBLL.GetModel(id);
            string password = FormsAuthentication.HashPasswordForStoringInConfigFile("PikerAdmin" + DateTime.Now.ToShortDateString(), "MD5");
            admin.AdminPwd = password;
            if (adminBLL.Update(admin))
            {
                MessageBox.Show(this.Page, "重置用户密码成功，新的密码为：" + password);
            }
            else
            {
                MessageBox.Show(this.Page, "重置用户密码失败！");
            }
        }
    }
}